/********************************************************************

Write Date: 2011/06/02
Author: Deng Nianchen
>>>> Add class OOPString to provide a char/wchar compatible string

Modify Date: 2011/07/29
Author: Deng Nianchen
>>>> Fix the bug in converting from / to std::string

Modify Date: 2011/12/22
Author: Deng Nianchen
>>>> Add convert function which is used for convert between OOPString
	 and other types
*********************************************************************/
#ifndef OOP_STRING_H
#define OOP_STRING_H
#include "OOPUtilsGlobal.hpp"
#include "OOPObject.h"
#include <string>
#include <sstream>
#include <ios>



_OOPUTILS_BEGIN


/**************************************************************************************************
 * <summary> Purpose: Subclass of std::wstring to provide support for single
 *					 byte character string
 * 					 Thread-Safe: the class is not thread-safe. </summary>
 * 
 * <remarks>  Deng Nianchen, 2011/06/02. </remarks>
 **************************************************************************************************/

class _EXPORT_UTILS_CLASS OOPString : public std::wstring, public OOPObject
{

public:

    /* wstring's constructors */
    OOPString ();
    OOPString (const OOPString & _Right);
    explicit OOPString (const _Alloc & _Al);
    OOPString (const OOPString & _Right, size_type _Roff,
            size_type _Count = npos);
    OOPString (const OOPString & _Right, size_type _Roff,
            size_type _Count, const _Alloc& _Al);
    OOPString (const wchar_t *_Ptr, size_type _Count);
    OOPString (const wchar_t *_Ptr, size_type _Count,
            const _Alloc & _Al);
    OOPString (const wchar_t * _Ptr);
    OOPString (const wchar_t * _Ptr, const _Alloc & _Al);
    OOPString (size_type _Count, wchar_t _Ch);
    OOPString (size_type _Count, wchar_t _Ch, const _Alloc & _Al);
    OOPString (const_pointer _First, const_pointer _Last);
    OOPString (const_pointer _First, const_pointer _Last,
            const _Alloc & _Al);
    OOPString (const_iterator _First, const_iterator _Last);
    OOPString (OOPString && _Right);
    template<class _It>
    OOPString (_It _First, _It _Last) : wstring (_First, _Last) {}
    template<class _It>
    OOPString (_It _First, _It _Last, const _Alloc& _Al)
            : wstring (_First, _Last, _Al) {}
	OOPString (const std::wstring & _Right) : std::wstring (_Right) {}
     
    std::string toStdString () const;

    std::wstring toStdWString () const;

	static OOPString fromStdString (const std::string & str);

	static OOPString fromStdWString (const std::wstring & str);

	template< class T >
	static T convertTo (const OOPString& str);

	template< class T >
	static OOPString convertFrom (const T& obj);

};

template< class T >
OOPString OOPUtils::OOPString::convertFrom (const T& obj)
{
	std::wostringstream converter;
	converter << obj;
	return OOPString::fromStdWString (converter.str ());
}

template< class T >
T OOPUtils::OOPString::convertTo (const OOPString& str)
{
	std::wistringstream converter (str);
	T obj;
	converter >> obj;
	return obj;
}


std::ostream & operator<< (std::ostream & outStream, const OOPString & str);



std::istream & operator>> (std::istream & inStream, OOPString & str);



_OOPUTILS_END



#endif